#!/bin/bash
 
source make_sandbox.cfg
 
IFS=$'\n';
 
echo '# step 2: import database and files >>> BEGIN';
# ============================================================
# step 2: import database and files
# ============================================================
 
echo "grabbing snapshot of source database from ${SOURCE_DATABASE}";
/usr/bin/mysqldump \
	${SOURCE_DATABASE} \
	-u${SOURCE_DATABASE_USER} \
	-p${SOURCE_DATABASE_PASS} \
	> ${TEMP_FILE}
 
 
echo `stat ${TEMP_FILE} -c "%n %s"` " bytes";
 
echo "importing snapshot into destination database ${DESTINATION_DATABASE}"
mysql -D \
	${DESTINATION_DATABASE} \
	-u${DESTINATION_DATABASE_USER} \
	-p${DESTINATION_DATABASE_PASS} \
	< ${TEMP_FILE}
 
 
echo "copying files from ${SOURCE_FOLDER}* to ${DESTINATION_FOLDER}";
cp -R -p --verbose ${SOURCE_FOLDER}* ${DESTINATION_FOLDER}
 
echo "chown'ing ${DESTINATION_FOLDER} as ${DESTINATION_CHOWN_USER_GROUP}";
chown -R ${DESTINATION_CHOWN_USER_GROUP} ${DESTINATION_FOLDER}*
 
echo "copying .htaccess manually";
cp --verbose ${SOURCE_FOLDER}.htaccess ${DESTINATION_FOLDER}.htaccess
echo "   adding to .htaccess: ${ADD_TO_HTACCESS}";
echo "${ADD_TO_HTACCESS}" >> ${DESTINATION_FOLDER}.htaccess

echo '# step 2: import database and files >>> END';
